Solomon probably never really meant to depart from the path God had set for him. He probably never intended to walk away in disobedience. But he began to compromise, particularly to social and cultural pressures, and maybe a bit too much enjoyment of his personal wealth and glory. And before he knew it, his family was filled with pagan wives and his kingdom was filled with sin.
First Kings carries on a theme that will run through the entire Old Testament. We are not to play with sin. That was the message of the prophets. Be true to God. No compromise.